package com.CGFrame.struts.action.categorySet;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.CGFrame.struts.POJOs.Catemodel;
import com.CGFrame.struts.bean.category.CateModelBean;
import com.CGFrame.struts.bean.category.CategoryBean;
import com.CGFrame.struts.bean.category.Catemodelrelbean;
import com.CGFrame.struts.bean.category.CatemodeltimeBean;

public class ModelDetailAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm from, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String modelId;
		if(request.getParameter("cateModelId")!=null){
			modelId=request.getParameter("cateModelId");
		//	System.out.println("request.getParameter:"+modelId);
		}else{
			modelId=(String)request.getAttribute("modelId");
		//	System.out.println("request.getAttribute:"+modelId);
		}
		
		CateModelBean cmb=new CateModelBean(Integer.valueOf(modelId));
		Catemodel model=cmb.getCatemodelById(modelId);
		request.setAttribute("modelName", model.getCateModelName());
		request.setAttribute("modelId", modelId);
		
		CatemodeltimeBean ctb = new CatemodeltimeBean();
		List list=ctb.getModelsById(modelId);
		request.setAttribute("list",list);
		
		Catemodelrelbean crb=new Catemodelrelbean();
		List relations=crb.getRelationsByModelId(modelId);
		request.setAttribute("relations",relations);
		
		CategoryBean cb=new CategoryBean();
		List cates=cb.getCategorys();
		request.setAttribute("cates", cates);
		
		return mapping.findForward("modeldetail");
	}
	
}
